package com.okRPC.client.handler;

import com.okRPC.client.cache.LocalRpcResponseCache;
import com.okRPC.common.RpcResponse;
import com.okRPC.protocol.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * Description: This is a sample class.
 * Author: Simon
 */
@Slf4j
public class RpcResponseHandler extends SimpleChannelInboundHandler<Message<RpcResponse>> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Message<RpcResponse> rpcResponseMessage) throws Exception {
        String requestId = rpcResponseMessage.getMessageHeader().getRequestId();
        // 收到响应 设置响应数据
        LocalRpcResponseCache.fillResponse(requestId, rpcResponseMessage);
    }

}
